package com.gitee.wsl.markdown.html

/**
 * @since 2.0.0
 */
abstract class MarkwonHtmlParser {
    interface FlushAction<T> {
        fun apply(tags: List<T>)
    }

    abstract fun <T> processFragment(
        output: T,
        htmlFragment: String
    ) where T : Appendable, T : CharSequence

    /**
     * After this method exists a [MarkwonHtmlParser] will clear internal state for stored tags.
     * If you wish to process them further after this method exists create own copy of supplied
     * collection.
     *
     * @param documentLength known document length. This value is used to close all non-closed tags.
     * If you wish to keep them open (do not force close at the end of a
     * document pass here [io.noties.markwon.html.HtmlTag.NO_END]. Later non-closed tags
     * can be detected by calling [io.noties.markwon.html.HtmlTag.isClosed]
     * @param action         [FlushAction] to be called with resulting tags ([io.noties.markwon.html.HtmlTag.Inline])
     */
    abstract fun flushInlineTags(
        documentLength: Int,
        action: FlushAction<HtmlTag.Inline>
    )

     fun flushInlineTags(
        documentLength: Int,
        action:(tags: List<HtmlTag.Inline>)->Unit
    ){
         flushInlineTags(documentLength,object:FlushAction<HtmlTag.Inline>{
             override fun apply(tags: List<HtmlTag.Inline>) {
                 action(tags)
             }
         })
    }

    /**
     * After this method exists a [MarkwonHtmlParser] will clear internal state for stored tags.
     * If you wish to process them further after this method exists create own copy of supplied
     * collection.
     *
     * @param documentLength known document length. This value is used to close all non-closed tags.
     * If you wish to keep them open (do not force close at the end of a
     * document pass here [io.noties.markwon.html.HtmlTag.NO_END]. Later non-closed tags
     * can be detected by calling [io.noties.markwon.html.HtmlTag.isClosed]
     * @param action         [FlushAction] to be called with resulting tags ([io.noties.markwon.html.HtmlTag.Block])
     */
    abstract fun flushBlockTags(
        documentLength: Int,
        action: FlushAction<HtmlTag>
    )

    abstract fun reset()
}